package com.wgc.goods.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wgc.goods.domain.Product;
import com.wgc.goods.service.ProductService;
import com.wgc.goods.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 15776
* @description 针对表【goods_product(商品表)】的数据库操作Service实现
* @createDate 2024-07-30 12:23:49
*/
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product>
    implements ProductService{
    @Autowired
    private ProductMapper iProductMapper;
    @Override
    public Integer audit(Long id, Integer audit) {
        Product product = new Product();
        product.setId(id);
        if (audit == 2) {
            //审核拒绝
            product.setAudit(audit);
            iProductMapper.updateById(product);
            return 2;
        }else if (audit == 1){
            //审核通过
            product.setAudit(audit);
            product.setStatus(1);
            iProductMapper.updateById(product);
            return 1;
        }
        return -1;
    }
    @Override
    public Integer status(Long id, Integer status) {
        Product product1 = iProductMapper.selectById(id);
        if (product1 == null || product1.getIsDelete() == 1) {
            return -1;
        }
        //上架
        if (status == 1) {

            Integer audit = product1.getAudit();
            if (audit != 1) {
                return -1;
            }
        }
        Product product = new Product();
        product.setId(id);
        product.setStatus(status);
        return iProductMapper.updateById(product);
    }

}




